﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using log4net;
using log4net.Config;

//[assembly: XmlConfigurator(ConfigFile = "log4net.config", Watch = true)] // 已在 App.xaml.cs 初始化
namespace NewChillers.Helpers
{
    public static class LogHelper
    {
        public static void Error(Type type, string info, string operatorName = "System")
        {
            var log = LogManager.GetLogger(type);
            log4net.ThreadContext.Properties["Operator"] = operatorName;
            log.Error(info);
        }

        public static void Error(Type type, string info, Exception ex, string operatorName = "System")
        {
            var log = LogManager.GetLogger(type);
            log4net.ThreadContext.Properties["Operator"] = operatorName;
            log.Error(info, ex);
        }

        public static void Warn(Type type, string info, string operatorName = "System")
        {
            var log = LogManager.GetLogger(type);
            log4net.ThreadContext.Properties["Operator"] = operatorName;
            log.Warn(info);
        }

        public static void Info(Type type, string info, string operatorName = "System")
        {
            var log = LogManager.GetLogger(type);

            // 设置Operator属性
            log4net.ThreadContext.Properties["Operator"] = operatorName;

            log.Info(info);
        }

        public static void DeBug(Type type, string info, string operatorName = "System")
        {
            var log = LogManager.GetLogger(type);
            log4net.ThreadContext.Properties["Operator"] = operatorName;
            log.Debug(info);
        }
    }
}
